app.controller("marketCtrl",["$scope","$http","$routeParams","goods","cart",function($scope,$http,$routeParams,goods,cart){
	$scope.list=["热销榜","天天特价","优选水果","牛奶面包","热销榜","天天特价","优选水果","牛奶面包","热销榜","天天特价","优选水果","牛奶面包","优选水果","牛奶面包"]
	$scope.listData=[];
	$scope.num=0;
	$scope.goods = goods;
//	$scope.text="热销榜"
	$scope.text=$routeParams.text || "热销榜";
	function requst(){
		if(!$scope.goods[$scope.text]){
			$http.get("http://h5.yztctech.net/api/axf/apicategory.php?category="+$scope.text)
			.success(function(data){
				$scope.goods[$scope.text]=data.data;
			})
		}
		
	}
	
	requst();
	
	$scope.getData = function(text,index){
		$scope.num=index;
		$scope.text=text;
		requst();
	}
	
	//加减圆圈的方法
	$scope.compute=function(i,num){
		if(i.num){
			i.num+=num;
		}else{
			i.num=1;
		}
		
		
		if(i.num>0){
			cart.addCart($scope.text+i.id,i);
			
		}else{
			cart.del($scope.text+i.id,i);
		}
	}
	
	
	
}])